
const location = window.location,
    origin = location.origin,
    pathname = location.pathname;

const tuanLink = 'https://app.hxsapp.com/hxswap/tuanList/index';
const onSiteProductDetailLink = origin + pathname.slice(0, pathname.lastIndexOf('/'));

/**
 * 构建团购的链接
 * @param {Object} params 需要拼在url后面的键值对
 */
export const buildTuanLink = params => tuanLink + '?' + 
    Object.keys(params)
        .reduce((prev, val)=>prev.concat(`${val}=${params[val]}`), [])
        .join('&');

/**
 * 构建内部商品详情链接地址
 * @param {string} id 商品id
 * @param {Object} params query参数
 */
export const buildOnSiteProductDetailLink = (id, params) => onSiteProductDetailLink + `/${id}?` + 
    Object.keys(params)
        .reduce((prev, val)=>prev.concat(`${val}=${params[val]}`), [])
        .join('&');